# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/27 上午9:18
 @Author  : tgy
 
"""
from ListNode import ListNode

def hasCycle(head: ListNode) -> bool:
    ...
    if not head or not head.next:
        return False
    slow_node = head
    fast_node = head
    while fast_node and fast_node.next:
        ...
        slow_node = slow_node.next
        fast_node = fast_node.next.next
        if fast_node == slow_node:
            break
    else:
        ...
        return False

    fast_node = head
    while fast_node != slow_node:
        fast_node = fast_node.next
        slow_node = slow_node.next

    print(fast_node.val)
    return True


if __name__ == '__main__':
    ...
    root = ListNode(1)
    root.next = ListNode(2)
    root.next.next = ListNode(3)
    root.next.next.next = ListNode(4)
    last_node = ListNode(5)
    root.next.next.next.next = last_node
    last_node.next = root.next.next
    hasCycle(root)
